import WaterDropComp from "../../engine/comps/WaterDropComp";
const { ccclass, property } = cc._decorator;

@ccclass
export default class WaterView extends cc.Component {

    @property(WaterDropComp)
    water: WaterDropComp = null;

    private clickNum: number = 0;
    start() {
        this.water.setFlow(true)
        this.water.setWaterLength(100)
        this.node.on(cc.Node.EventType.TOUCH_START, this.touchStart, this)
        this.node.on(cc.Node.EventType.TOUCH_MOVE, this.touchMove, this)
        this.node.on(cc.Node.EventType.TOUCH_END, this.touchEnd, this)
        this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.touchEnd, this)


    }



    touchStart(e: cc.Touch) {
        let point = this.node.convertToNodeSpaceAR(e.getLocation());
        this.water.clearMask(point, this.clickNum++);

    }

    touchMove(e: cc.Touch) {
        let point = this.node.convertToNodeSpaceAR(e.getLocation());
        this.water.clearMask(point, this.clickNum++);
    }

    touchEnd(e: cc.Touch) {

    }

    onButtonSwapClick() {
        this.water.swap()
        this.water.reset();
        this.clickNum = 0;
    }
    // update (dt) {}
}
